*******************************
* IRCA and Redistricting
* Navid Sabet and Noam Yuchtman
* Figure 6: IRCA and district compactness (PP and Reock)
*******************************

//Load data
	use irca_gerrymander.dta, clear
		
	//Controls
	global controls  c.pop1990#i.p102 c.inc_pc1990#i.p102  c.age_share1990#i.p102 c.unemployment_1990#i.p102 c.educ1990##i.p102 c.births_1990#i.p102 c.black_share1990#i.p102 c.white_share1990#i.p102
	
	//Fully interacted controls
	global controls_full  c.pop1990##i.p102##i.legal_control_kaplan1991 c.inc_pc1990##i.p102##i.legal_control_kaplan1991  c.age_share1990##i.p102##i.legal_control_kaplan1991 c.unemployment_1990##i.p102##i.legal_control_kaplan1991 c.educ1990##i.p102##i.legal_control_kaplan1991 c.births_1990##i.p102##i.legal_control_kaplan1991 c.black_share1990##i.p102##i.legal_control_kaplan1991 c.white_share1990##i.p102##i.legal_control_kaplan1991
	
	//VRA Controls: 
	global vra_control i.vra_covered##i.p102
	global vra_full i.vra_covered##i.p102##i.legal_control_kaplan1991 
	
	//Extra controls
	global extras c.povrate_1990#i.p102 c.hsd_share1990#i.p102 c.spr010_1990#i.p102 c.spr030_1990#i.p102 c.housing_value_1990#i.p102 c.crime_1990#1.p102
	
	 //1980 Controls
	global controls1980 c.population_bea1980#i.p102 c.income_pc1980#i.p102  c.age_share1980#i.p102 c.edu6351980#i.p102 c.births_1980#i.p102 c.black_share1980#i.p102 c.white_share1980#i.p102
	
	//Controls pre post 1980 redistricting (placebo model controls)
	global controls97 c.pop1990#i.p97 c.inc_pc1990#i.p97  c.age_share1990#i.p97 c.unemployment_1990#i.p97 c.educ1990##i.p97 c.births_1990#i.p97 c.black_share1990#i.p97 c.white_share1990#i.p97
		
	//VRA controls: pre post 1980 redistricting (placebo model controls)
	global vra_control97 i.vra_covered##i.p97
	
	//Fixed effects
	global fe id congress#StateFIPS c.hisp_share1980#i.congress i.unassigned_county#i.congress 
	
	//Clustering
	global cluster id

	//Generate filler variables.
	gen x_base = legal_control_kaplan1991
	gen x_none = legal_control_kaplan1991
	gen x_extra = legal_control_kaplan1991
	gen x_1980 = legal_control_kaplan1991
	gen x_full = legal_control_kaplan1991
	gen x_arp = arp_nocommission
	gen x_hisp = legal_control_kaplan1991
	gen x_treated = legal_control_kaplan1991
	gen x_single = legal_control_kaplan1991
	gen x_mm = legal_control_kaplan1991
	gen x_placebo = legal_control_kaplan1981
	
****************
* Poslpy Popper 
****************
eststo clear
	 //Baseline
	reghdfe pp_county $controls $vra_control c.irca_std##1.p102##ib2.x_base [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo base
	sum pp_county if e(sample) & p102==0
	
	 //No controls
	reghdfe pp_county c.irca_std##i.p102##ib2.x_none [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo none
	
	//Extra controls
	reghdfe pp_county $controls $vra_control $extras c.irca_std##i.p102##ib2.x_extra [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo extra
	
	//1980 Controls
	reghdfe pp_county $controls1980 $vra_control c.irca_std##i.p102##ib2.x_1980 [weight = cuts] , a($fe) cluster($cluster)	
	estadd scalar clusters = e(N_clust)
	eststo 	eighty
	
	//Interacted Observables (Fully Saturated)
	reghdfe pp_county $controls_full $vra_full c.irca_std##i.p102##ib2.x_full [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo full
	
	//Alternative Definition of Legal Control
	reghdfe pp_county  $controls $vra_control c.irca_std##i.p102##ib2.x_arp [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo arp
	
	//Using Hispanic share instead of imputing
	reghdfe pp_county $controls $vra_control c.irca_pc1990_hisp_std##i.p102##ib2.x_hisp [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo hisp
	
	//Drop imputed counties
	reghdfe pp_county $controls $vra_control c.irca_std##i.p102##ib2.x_treated if unassigned_county == 0 [weight = cuts], a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo no_impute
	
	 //Only single district counties
	reghdfe pp_county $controls $vra_control c.irca_std##1.p102##ib2.x_single [weight = cuts] if cuts==1, a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo single_dist
	
	//Drop minority-majority counties
	reghdfe pp_county $controls $vra_control c.irca_std##1.p102##ib2.x_mm [weight = cuts] if hisp_majority_county==0 & black_majority==0, a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo mm
	
	//Falsification
	reghdfe pp_county $controls97 $vra_control97 c.irca_std##i.p97##ib2.x_placebo [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo placebo
	 
				
****************
* Reock
****************

	 //Baseline
	reghdfe reo_county $controls $vra_control c.irca_std##1.p102##ib2.x_base [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo base_reo
	sum reo_county if e(sample) & p102==0
	
	 //No controls
	reghdfe reo_county c.irca_std##i.p102##ib2.x_none [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo none_reo
	
	//Extra controls
	reghdfe reo_county $controls $vra_control $extras c.irca_std##i.p102##ib2.x_extra [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo extra_reo
	
	//1980 Controls
	reghdfe reo_county $controls1980 $vra_control c.irca_std##i.p102##ib2.x_1980 [weight = cuts] , a($fe) cluster($cluster)	
	estadd scalar clusters = e(N_clust)
	eststo 	eighty_reo
	
	//Interacted Observables (Fully Saturated)
	reghdfe reo_county $controls_full $vra_full c.irca_std##i.p102##ib2.x_full [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo full_reo
	
	//Alternative Definition of Legal Control
	reghdfe reo_county $controls $vra_control c.irca_std##i.p102##ib2.x_arp [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo arp_reo
	
	//Using Hispanic share instead of imputing
	reghdfe reo_county $controls $vra_control c.irca_pc1990_hisp_std##i.p102##ib2.x_hisp [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo hisp_reo
	
	//Drop imputed counties
	reghdfe reo_county $controls $vra_control c.irca_std##i.p102##ib2.x_treated if unassigned_county == 0 [weight = cuts], a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo no_impute_reo
	
	 //Only single district counties
	reghdfe reo_county $controls $vra_control c.irca_std##1.p102##ib2.x_single [weight = cuts] if cuts==1, a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo single_dist_reo
	
	//Drop minority-majority counties
	reghdfe reo_county $controls $vra_control c.irca_std##1.p102##ib2.x_mm [weight = cuts] if hisp_majority_county==0 & black_majority==0, a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo mm_reo
	
	//Falsification
	reghdfe reo_county $controls97 $vra_control97 c.irca_std##i.p97##ib2.x_placebo [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo placebo_reo 
	

***********
* Plot the Coefficients
***********
	
	//Headings
	coefplot base none extra eighty full arp hisp no_impute single_dist mm placebo, bylabel("(a) Polsby-Popper") ///
		||  base_reo none_reo extra_reo eighty_reo full_reo arp_reo hisp_reo no_impute_reo single_dist_reo mm_reo placebo_reo,  bylabel("(b) Reock") ///
		|| , keep(1.p102#1.x_base#c.irca_std ///
			1.p102#1.x_none#c.irca_std ///
			1.p102#1.x_extra#c.irca_std ///
			1.p102#1.x_1980#c.irca_std ///
			1.p102#1.x_full#c.irca_std ///
			1.p102#1.x_arp#c.irca_std ///
			1.p102#1.x_hisp#c.irca_pc1990_hisp_std ///
			1.p102#1.x_treated#c.irca_std ///
			1.p102#1.x_single#c.irca_std ///
			1.p102#1.x_mm#c.irca_std ///
			1.p97#1.x_placebo#c.irca_std) ///
			xlabel(-6(4)4) xscale(range(-6(4)4)) /// ///
			coeflabels(1.p102#1.x_base#c.irca_std = "Baseline (1)" ///
						1.p102#1.x_none#c.irca_std = "No Controls (2)" ///
						1.p102#1.x_extra#c.irca_std = "Extra Controls (3)" ///
						1.p102#1.x_1980#c.irca_std = "1980 Controls (4)" /// 
						1.p102#1.x_full#c.irca_std = "Fully Interacted (5)" /// 
						1.p102#1.x_arp#c.irca_std = "Legal Control (6)" /// 
						1.p102#1.x_hisp#c.irca_pc1990_hisp_std = "Hispanic Imputation (7)" /// 
						1.p102#1.x_treated#c.irca_std = "No Imputation (8)" /// 
						1.p102#1.x_single#c.irca_std = "Single Districts (9)" ///
						1.p102#1.x_mm#c.irca_std = "Drop MM (10)" ///
						1.p97#1.x_placebo#c.irca_std = "1980 Placebo (11)") ///
						headings(1.p102#1.x_base#c.irca_std = `"{bf:Empirical Specifications}"'        ///
								1.p102#1.x_treated#c.irca_std = `"{bf:Sample Restrictions}"'                     ///
							   1.p97#1.x_placebo#c.irca_std = `""{bf:Placebo}" ""' ) ///
							   byopts(legend(off)) ///
							   xline(0, ) ciopts(recast(rcap) lcolor(gs8)) msymbol(smcircle) grid(none) offset(1/128) 
							   
	
		graph export fig6.pdf, replace
		graph save fig6.gph, replace
	
	
